package com.example.activity

import android.content.ComponentName
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
import android.view.MotionEvent
import android.view.View
import android.widget.RelativeLayout
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentActivity
import com.example.activity.fragment.Find_Fragment
import com.example.activity.fragment.Me_Fragment
import com.example.activity.fragment.Message_Fragment
import com.example.activity.fragment.Wechat_Fragment
import com.example.activity.fragment.game.view.HatView
import kotlinx.android.synthetic.main.me_fragment.*
import java.lang.RuntimeException

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    /**
     * fragment切换函数
     */
    fun openFragment(view: View) {
        val ft = supportFragmentManager.beginTransaction()
        when(view.id){
            R.id.f_btn1 -> ft.replace(R.id.fragment,Find_Fragment())
            R.id.f_btn2 -> ft.replace(R.id.fragment,Me_Fragment())
            R.id.f_btn3 -> ft.replace(R.id.fragment,Message_Fragment())
            R.id.f_btn4 -> ft.replace(R.id.fragment,Wechat_Fragment())
            else -> throw RuntimeException("找不到该按键的id！")
        }
        ft.commit()
    }

    /**
     * intent动作
     */
    fun intentAction(view: View) {
        var intent = Intent()
        when(view.id){
            R.id.intent_btn1 -> {
                intent.action = Intent.ACTION_DIAL
                intent.data = Uri.parse("tel:15677097947")
            }
            R.id.intent_btn2 -> {
                intent.action = Intent.ACTION_SENDTO
                intent.data = Uri.parse("smsto:15677097947")
                intent.putExtra("sms_body","hello rookie andriod!")
            }
            R.id.intent_btn3 -> {
                //从该activity退回到桌面
                intent.action = Intent.ACTION_MAIN
                //设置这个动作的一些细节（标记）
                intent.flags = Intent.FLAG_ACTIVITY_NO_HISTORY
                intent.addCategory(Intent.CATEGORY_HOME)
            }
            R.id.intent_btn4 -> {
                //实现查看大图
                intent.action = Intent.ACTION_VIEW
            }
            R.id.intent_btn5 -> {
                //打开小游戏界面
                intent.component = ComponentName("com.example.activity","com.example.activity.GameActivity")
            }
            R.id.intent_btn6 -> {
                //启动图册
                intent.component = ComponentName("com.example.activity","com.example.activity.AlbumActivity")
            }
            R.id.intent_btn7 -> {
                //手势识别
                intent.component = ComponentName("com.example.activity","com.example.activity.GestureActivity")
            }
            R.id.intent_btn8 -> {
                //设置界面
                intent.component = ComponentName("com.example.activity","com.example.activity.MenuActivity")
            }
            R.id.intent_btn9 -> {
                //设置界面
                intent.component = ComponentName("com.example.activity","com.example.activity.ContextMenuActivity")
            }
            R.id.intent_btn10 -> {
                supportActionBar!!.show()
                return
            }
            R.id.intent_btn11 -> {
                supportActionBar!!.hide()
                return
            }
            R.id.intent_btn12 -> {
                intent.component = ComponentName("com.example.activity","com.example.activity.TabBarActivity")
            }
            R.id.intent_btn13 -> {
                intent.component = ComponentName("com.example.activity","com.example.activity.AlarmActivity")
            }
            else -> Toast.makeText(this,"你应该还没有设置这个按钮的相关设置吧!",Toast.LENGTH_LONG).show()
        }

        startActivity(intent)
    }


    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.main_menu,menu)
        return super.onCreateOptionsMenu(menu)
    }

}
